package test;

import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

import org.axe.Axe;
import org.axe.constant.ConfigConstant;
import org.axe.extra.timer.TimerTask;
import org.axe.helper.base.ConfigHelper;
import org.axe.helper.ioc.ClassHelper;
import org.axe.interface_.mvc.AfterClassLoaded;
import org.axe.interface_.mvc.AfterConfigLoaded;
import org.axe.interface_.mvc.Listener;
import org.axe.util.LogUtil;

public class BuildTables {
	public static void main(String[] args) {
		try {
			ConfigHelper.addAfterConfigLoadedCallback(new AfterConfigLoaded() {
				@Override
				public void doSomething(Properties config) {
					config.put("jdbc.datasource.axe-datasource-dbcp.auto_create_table", "true");
					config.put(ConfigConstant.JDBC_URL, "jdbc:mysql://192.168.199.45:3306/tunnel_dev?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE");
				}
			});
			ClassHelper.addAfterClassLoadedCallback(new AfterClassLoaded() {
				@Override
				public void doSomething(Set<Class<?>> classSet) {
					Set<Class<?>> classesRemove = new HashSet<>();
					for(Class<?> cls:classSet){
						if(Listener.class.isAssignableFrom(cls)){
							classesRemove.add(cls);
						}
						if(TimerTask.class.isAssignableFrom(cls)){
							classesRemove.add(cls);
						}
					}
					classSet.removeAll(classesRemove);
				}
			});
			Axe.init();
			
		} catch (Exception e) {
			LogUtil.error(e);
		}
		System.exit(0);
	}
}
